package com.szgr.baoyin.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.szgr.baoyin.MyApplication;
import com.szgr.baoyin.R;
import com.szgr.baoyin.activity.ApplyCardActivity;
import com.szgr.baoyin.activity.LoginActivity;
import com.szgr.baoyin.activity.VipApplyActivity;
import com.szgr.baoyin.activity.VipArticleActivity;
import com.szgr.baoyin.activity.VipCardActivity;
import com.szgr.baoyin.activity.VipRuleActivity;
import com.szgr.baoyin.utils.Constant;

/**
 * A simple {@link Fragment} subclass.
 */
public class ReduceFragment extends Fragment implements View.OnClickListener{


    public ReduceFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_main_reduce,container,false);
        initView(view);
        return view;
    }

    public void initView(View view) {
        View btn_apply = view.findViewById(R.id.vip_rule_apply_vip);
        View btn_detail = view.findViewById(R.id.vip_rule_back);
        btn_detail.setOnClickListener(this);
        btn_apply.setOnClickListener(this);

//        Intent intent = getIntent();
//        if(intent != null && intent.hasExtra("from")){
//            btn_apply.setVisibility(View.GONE);
//            btn_detail.setVisibility(View.GONE);
//        }
        String url = Constant.URL_VIP_02;
//        if(intent != null && intent.hasExtra("myself")){
//            btn_apply.setVisibility(View.GONE);
//            btn_detail.setVisibility(View.GONE);
//            url = Constant.URL_VIP_01;
////            actionBarTitle.setText("会员手册");
//        }

        WebView webView = (WebView) view.findViewById(R.id.vip_rule_web_view);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        webView.loadUrl(url);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.vip_rule_back:
                if(MyApplication.getmInstance().isLogin()) {
                    startActivity(new Intent(getActivity(), ApplyCardActivity.class));
                }else{
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }
                break;
            case R.id.vip_rule_apply_vip:
                Intent intent = new Intent(getActivity(), VipRuleActivity.class);
                intent.putExtra("myself","myself");
                startActivity(intent);
                break;
        }
    }

}
